<#include "../header.ftl" />
<@head title="站内消息" />
		<@side.sidenav active="站内消息"/>
	    <div class="g-content">
	        <div class="g-content-container">
	            <div class="g-p">
					<div class="m-crumb">
					    <ul class="f-cb">
					        <li><i>&gt;</i><a href="${spaceUrl}/admin">博客管理</a></li>
					        <li><i>&gt;</i><a href="javascript:void(0);">站内消息</a></li>
					    </ul>
					</div>
					<div class="page-title">
						<h1>站内消息</h1>
					</div>
					<div class="m-content">
						<div class="tab">
							<ul class="tab-title clearfix">
								<li class="tab-title-item <#if filter=="all">active</#if>"><a href="${spaceUrl}/admin/message?filter=all" data-toggle="tab">所有消息</a></li>
						   		<li class="tab-title-item <#if filter=="unread">active</#if>"><a href="${spaceUrl}/admin/message?filter=unread" data-toggle="tab">未读消息</a></li>
						 	</ul>
						</div>
						<div class="tab-content">
							<form name="messageForm" id="messageForm" action="${spaceUrl}/admin/message" method="GET">
								<@spring.bind "messagePage" />
								<!-- pagination parameter -->
								<@spring.formHiddenInput path="messagePage.pageNo" />
								<@spring.formHiddenInput path="messagePage.totalPages" />
								<@spring.formHiddenInput path="messagePage.totalCount" />
								<!-- sorter parameter -->
								<@spring.formHiddenInput path="messagePage.sortEnable" />
								<@spring.formHiddenInput path="messagePage.sort.field" />
								<@spring.formHiddenInput path="messagePage.sort.order" />
								
						    	<#if (messagePage?exists && messagePage.result?size > 0)>
						    		<div id="medias" class="sep">
							        	<#list messagePage.result as message>
								    		<div class="media last">
							        			<#if message.sender?exists>
							        			<a href="#" class="media-cap"><img src="<@avatar avatar=message.sender.smallAvatar/>"></a>
							        			</#if>
							        			<div class="media-body">
							        				<div class="media-body-title">
							        					<#if message.sender?exists>
							        					<strong>${message.sender.alias} @ ${message.messageText.createTime?string("yyyy-MM-dd hh:mm:ss")}</strong>
							        					<#else>
							        					<strong>系统@${message.messageText.createTime?string("yyyy-MM-dd hh:mm:ss")}</strong>
							        					</#if>
							        					<small class="pull-right">
							        						<a style="color:#ec5524;" href="javascript:deleteMessage(this, ${message.id});">删除</a>
							        					</small>
							        				</div>
							        				<p class="typo-p">
							        					${message.messageText.content}
							        				</p>
							        			</div>
							        		</div>
								    	</#list>
							    	</div>
							    <#else>
							    	<a class="listpub" href="${spaceUrl}/admin/message/create" class="sep"><i class="icon-plus"></i><span>&nbsp;暂无消息</span></a>
					        	</#if>
							    <#if (messagePage.totalPages > 1)>
			                        <@space.pagenavi pageEntity=messagePage baseUrl=spaceUrl + "/admin/message?filter=${filter!''}pageNo=$page$" />
			                    </#if>
							</form>
						</div>
					</div>
	            </div>
	        </div>
	    </div>
	    <script type="text/javascript">
	    	function deleteMessage(o, id){
	    		if(!confirm('确认删除该消息吗？')){
	    			return;
	    		}
	    		$.post('${spaceUrl}/admin/message/delete?id=' + id, function(){
	    			var pageNo = $('#pageNo').val();
	    			var url = '${spaceUrl}/admin/message?filter=${filter!""}';
	    			if(pageNo){
	    				url = url + '&pageNo=' + pageNo;
	    			}
	    			window.location.href = url;
	    		});
	    	}
	    	
	    	<#if filter=="unread">
	    	$(document).ready(function(){
	    		$.post('${spaceUrl}/admin/message/setReaded');
	    	});
	    	</#if>
	    </script>
<#include "../footer.ftl" />